package com.tt.fashionWebSite.domain;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * Created by 10520_000 on 10/30/14.
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "san_pham")
@NamedQueries({
      @NamedQuery(name = "getProductByIdDMSP",query = "SELECT s FROM SanPhamFull s " +
            "WHERE s.loaiDanhMucSanPham.maLoaiDMSP = :idDMSP AND s.doiTuong = :gender") ,
      @NamedQuery(name = "sanPhamFull.getProductAllByGender",query = "SELECT s FROM SanPhamFull s " +
            "WHERE s.doiTuong = :gender AND (s.loaiDanhMucSanPham.loaiDanhMuc.maLoai = 'LDM1' OR s.loaiDanhMucSanPham.loaiDanhMuc.maLoai = 'LDM2')" ) ,
      @NamedQuery(name = "sanPhamFull.getProductSearch",query = "SELECT s FROM SanPhamFull s " +
            "WHERE s.tenSP LIKE :name " ) ,
      @NamedQuery(name = "sanPhamFull.getProductAll",query = "SELECT s FROM SanPhamFull s order by s.maSP asc ") ,
/*      @NamedQuery(name = "getProductForDeal",query = "SELECT s FROM SanPhamFull s " +
            "WHERE s.chiTietSanPhams.mauSac.maMau = :color AND s.chiTietSanPhams.kichThuoc.maSize = :size AND s.chiTietSanPhams.hoaTiet.maHoaTiet = :motif") ,*/
})
public class SanPhamFull implements Serializable {
   public static final String GET_PRODUCT_BY_DMSP = "getProductByIdDMSP";
   public static final String GET_ALL_BY_GENDER = "sanPhamFull.getProductAllByGender";
   public static final String GET_SEARCH = "sanPhamFull.getProductSearch";
   public static final String GET_All = "sanPhamFull.getProductAll";
   public static final String GET_PRODUCT_FOR_DEAL = "getProductForDeal";

   @Id
   @Column(name = "MA_SP")
   private String maSP;

   @ManyToOne
   @JoinColumn(name = "MA_LOAI_DM_SP")
   private LoaiDanhMucSanPham loaiDanhMucSanPham;

   @Column(name = "TEN_SP")
   private String tenSP;

   @Column(name = "THONG_TIN")
   private String thongTin;

   @Column(name = "DOI_TUONG")
   private String doiTuong;

   @LazyCollection(LazyCollectionOption.FALSE)
   @OneToMany(mappedBy = "sanPham", cascade = {CascadeType.ALL}, orphanRemoval = true)
   private List<ChiTietSanPhamFull> chiTietSanPhams;

   public String getMaSP() {
      return maSP;
   }

   public void setMaSP(String maSP) {
      this.maSP = maSP;
   }

   public String getTenSP() {
      return tenSP;
   }

   public void setTenSP(String tenSP) {
      this.tenSP = tenSP;
   }

   public String getThongTin() {
      return thongTin;
   }

   public void setThongTin(String thongTin) {
      this.thongTin = thongTin;
   }

   public LoaiDanhMucSanPham getLoaiDanhMucSanPham() {
      return loaiDanhMucSanPham;
   }

   public void setLoaiDanhMucSanPham(LoaiDanhMucSanPham loaiDanhMucSanPham) {
      this.loaiDanhMucSanPham = loaiDanhMucSanPham;
   }

   public String getDoiTuong() {
      return doiTuong;
   }

   public void setDoiTuong(String doiTuong) {
      this.doiTuong = doiTuong;
   }

   public List<ChiTietSanPhamFull> getChiTietSanPhams() {
      return chiTietSanPhams;
   }

   public void setChiTietSanPhams(List<ChiTietSanPhamFull> chiTietSanPhams) {
      this.chiTietSanPhams = chiTietSanPhams;
   }
}
